package com.mstanford.movie.controller;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.mstanford.movie.dao.MovieDao;
import com.mstanford.movie.utils.DataUtil;

public class UpdateServlet extends HttpServlet {


	private static final long serialVersionUID = 1L;
	
	public void service(HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException{
		req.setCharacterEncoding("utf-8");
		String name = req.getParameter("name");
		String gender = req.getParameter("gender");
		String phone = req.getParameter("phone");
		String memberId = req.getParameter("memberId");
		
		
		Map<String,String> map = new HashMap<String,String>();
		map.put("name", name);
		map.put("gender", gender);
		map.put("phone", phone);
		map.put("memberId", memberId);
		MovieDao dao= new MovieDao();
		
		boolean flag = dao.updateMemberData(map);
		if(flag){
			map.put("Data", "true");
		}
		
		String json = DataUtil.mapToJson(map);

		res.setContentType("application/json; charset=UTF-8");
		PrintWriter out = res.getWriter();
		
		out.print(json);
		out.flush();
		out.close();
	}

}
